package com.music.twitter.client;

import org.springframework.beans.factory.annotation.Required;

import com.music.service.twitter.beans.TwitterServiceBean;
import com.music.service.twitter.service.TwitterService;
import com.music.twitter.beans.TwitterClientBean;

public class TwitterClientImpl implements TwitterClient {
	private TwitterService mTwitterService;

	/**
	 * @return the twitterService
	 */
	public TwitterService getTwitterService() {
		return mTwitterService;
	}

	/**
	 * @param pTwitterService
	 *            the twitterService to set
	 */
	@Required
	public void setTwitterService(TwitterService pTwitterService) {
		mTwitterService = pTwitterService;
	}

	public void deleteTwitter(Long pMemberId) {
		getTwitterService().deleteTwitter(pMemberId);
	}

	public TwitterClientBean getTwitter(Long pMemberId) {
		TwitterServiceBean twitterServiceBean = getTwitterService().getTwitter(
				pMemberId);
		if (twitterServiceBean != null) {
			// Convert service bean to client bean.
			return new TwitterClientBean(twitterServiceBean);
		} else {
			return null;
		}
	}

	public TwitterClientBean insertTwitter(TwitterClientBean pTwitter) {

		// Convert client bean to service bean.
		TwitterServiceBean twitterServiceBean = new TwitterServiceBean(pTwitter
				.getMemberId(), pTwitter.getAccessToken().getToken(), pTwitter
				.getAccessToken().getTokenSecret(),pTwitter.getTwitterId());
		twitterServiceBean = getTwitterService().insertTwitter(
				twitterServiceBean);
		if (twitterServiceBean != null) {
			// Convert service bean to client bean.
			return new TwitterClientBean(twitterServiceBean);
		} else {
			return null;
		}
	}

}
